﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Diagnostics;
using System.Reflection;


namespace Awesome_Shutdown_Timer
{
    public struct WhatsNewEntry
    {
        public Version version;
        public string[] changes;
    }
    public struct UpdateInfo
    {
        public Version latestVersion;
        public string updateUri;
        public WhatsNewEntry[] whatsNew;
    }

    /// <summary>
    /// Interaction logic for wndUpdate.xaml
    /// </summary>
    public partial class wndUpdate : Window
    {
        public static UpdateInfo updateInfo;


        public wndUpdate()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // versions
            lblCurrentVersion.Content =
                Assembly.GetExecutingAssembly().GetName().Version.Major.ToString() + "." +
                Assembly.GetExecutingAssembly().GetName().Version.MajorRevision.ToString() + "." +
                Assembly.GetExecutingAssembly().GetName().Version.Minor.ToString() + " build " +
                Assembly.GetExecutingAssembly().GetName().Version.MinorRevision.ToString();
            lblLatestVersion.Content =
                updateInfo.latestVersion.Major.ToString() + "." +
                updateInfo.latestVersion.MajorRevision.ToString() + "." +
                updateInfo.latestVersion.Minor.ToString() + " build " +
                updateInfo.latestVersion.MinorRevision.ToString();

            tbWhatsNew.Inlines.Clear();
            int c = 0;
            foreach(string s in updateInfo.whatsNew[0].changes)
            {
                if (c != 0) tbWhatsNew.Inlines.Add(new LineBreak());
                tbWhatsNew.Inlines.Add(new Run(s));
                c++;
            }
        }

        public void ShowDialog(Window owner)
        {
            this.Owner = owner;
            this.ShowDialog();
        }

        public void Show(Window owner)
        {
            this.Owner = owner;
            this.Show();
        }

        //--------------------------------------------------

        private void cmdDownload_Click(object sender, RoutedEventArgs e)
        {
            Process.Start(new ProcessStartInfo(updateInfo.updateUri));
        }

        private void cmdCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }


    }
}
